package yangsw87.basic;

public class J15_Ex72_Interface {

	public static void main(String[] args) {
		J15_RectangleServiceImpl resrv = new J15_RectangleServiceImpl();

		J15_Rectangle re = new J15_Rectangle(4, 40, "red");

		re.setArea(resrv.getArea(re));
		re.setCircum(resrv.getCircum(re));
		System.out.println(re.toString());

		J15_Rectangle re1 = new J15_Rectangle(3.5, 35.9, "orange");
		re1.setArea(resrv.getArea(re1));
		re1.setCircum(resrv.getCircum(re1));
		System.out.println(re1.toString());

	} // class

} // main

interface J15_RectangleService {
	double getArea(J15_Rectangle re);

	double getCircum(J15_Rectangle re);
}

class J15_RectangleServiceImpl implements J15_RectangleService {

	@Override
	public double getArea(J15_Rectangle re) {
		double area = re.getWidth() * re.getHeight();
		return area;
	}

	@Override
	public double getCircum(J15_Rectangle re) {
		double circum = (re.getWidth() + re.getHeight()) * 2;
		return circum;
	}

}

class J15_Rectangle {
	private double width;
	private double height;
	private String color;

	private double area;
	private double circum;

	public J15_Rectangle() {
		double width = 1.0;
		double height = 1.0;
		String color = "white";
	}

	public J15_Rectangle(double width, double height, String color) {
		this.width = width;
		this.height = height;
		this.color = color;
	}

	public double getWidth() {
		return width;
	}

	public void setWidth(double width) {
		this.width = width;
	}

	public double getHeight() {
		return height;
	}

	public void setHeight(double height) {
		this.height = height;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public double getArea() {
		return area;
	}

	public void setArea(double area) {
		this.area = area;
	}

	public double getCircum() {
		return circum;
	}

	public void setCircum(double circum) {
		this.circum = circum;
	}

	@Override
	public String toString() {
		return "J15_Rectangle [width=" + width + ", height=" + height
				+ ", color=" + color + ", area=" + area + ", circum=" + circum
				+ "]";
	}

}